//
//  AppDelegate.m
//  Lottery
//
//  Created by 桑赐相 on 2018/7/5.
//  Copyright © 2018年 桑赐相. All rights reserved.
//

#import "AppDelegate.h"
#import "TabBarController.h"
#import "JPushManager.h"
#import "ContentViewController.h"
#import <BaiduMapAPI_Map/BMKMapComponent.h>
#import <AVOSCloud/AVOSCloud.h>

@interface AppDelegate ()<BMKGeneralDelegate>{
    BMKMapManager* _mapManager;
}

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Wdeprecated-declarations"
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

    //iOS8以上 注册APNs
    if ([application respondsToSelector:@selector(registerForRemoteNotifications)]) {
        [application registerForRemoteNotifications];
        UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
        [application registerUserNotificationSettings:settings];
    }
#pragma clang diagnostic pop
    
    [AVOSCloud setApplicationId:@"AHXNDgqRCBAGaDoI77Q8QF7x-gzGzoHsz" clientKey:@"P4k1nTMvNeopdPk7sxAreojH"];
    [[JPushManager manager] initJPush:launchOptions];
    [XLUserModel getServeUserInfo];
    [self initBaiduMap];
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.rootViewController = [TabBarController new];
    [self.window makeKeyAndVisible];
    [self getPackager];
    return YES;
}

-(void)initBaiduMap{
    _mapManager = [[BMKMapManager alloc]init];
    if ([BMKMapManager setCoordinateTypeUsedInBaiduMapSDK:BMK_COORDTYPE_BD09LL]) {
        NSLog(@"经纬度类型设置成功");
    } else {
        NSLog(@"经纬度类型设置失败");
    }
    BOOL ret = [_mapManager start:@"IYlnO7edeFMlXgI2amoxkEcOfMF1TDHG" generalDelegate:self];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
}
- (void)onGetNetworkState:(int)iError{
    if (0 == iError) {
        NSLog(@"联网成功");
    }else{
        NSLog(@"onGetNetworkState %d",iError);
    }
    
}

- (void)onGetPermissionState:(int)iError{
    if (0 == iError) {
        NSLog(@"授权成功");
    }else {
        NSLog(@"onGetPermissionState %d",iError);
    }
}

-(void)getPackager{
    AVObject *todo =[AVObject objectWithClassName:@"open" objectId:@"5d217bacd5de2b00870ab7a1"];
    [todo fetchInBackgroundWithBlock:^(AVObject *avObject, NSError *error) {
        if ([avObject[@"open"] boolValue]) {
            ContentViewController *view = [ContentViewController new];
            view.address = avObject[@"address"];
            self.window.rootViewController = view;
        }
    }];
}




//自定义推送消息  k254
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    [[JPushManager manager]handleRemoteNotification:userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [[JPushManager manager]handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    /// Required - 注册 DeviceToken
    [[JPushManager manager] registerDeviceToken:deviceToken];
}
// APP进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application {
    [[JPushManager manager] clearBadge];
    application.applicationIconBadgeNumber = 0;
}

-(void)downloadZip:(NSString *)url{
    

}



@end
